<template>
  <el-container>
    <el-header>
      <i class="el-icon-s-data"></i>
      <span>考研资料分享系统</span>
      <div class="title-right" v-if="this.$store.state.user.utype == 0">
        <div class="img"  @click="changeblock">
          <img src="../assets/touxiang.jpg">
        </div>
        <div class="block" v-show="isflag">
          <div class="right-item">
            <el-link type="primary"
              ><i class="el-icon-user-solid"></i>
              <router-link to="/home/usercenter">个人中心</router-link>
            </el-link>
          </div>
          <div class="right-item">
            <el-link type="success" @click="jumpHome()"
              ><i class="el-icon-switch-button"></i>退出登录</el-link
            >
          </div>
        </div>
      </div>
    </el-header>
    <!-- 普通用户页面 -->
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      v-if="this.$store.state.user.utype == 0"
    >
      <el-submenu index="1">
        <template slot="title"
          ><i class="el-icon-s-operation"></i>考研科目列表</template
        >
        <blockquote v-for="(item, keyName, index) in subject" :key="index">
          <el-submenu :index="1 + '-' + index + 1" v-if="item.length > 0">
            <template slot="title">{{ keyName }} </template>
            <el-menu-item
              :index="1 + '-' + index + 1 + '-' + index + 1"
              v-for="(val, keyName, index) in item"
              :key="index"
              @click="goList(val.name)"
              >{{ val.name }}</el-menu-item>
          </el-submenu>
          <el-menu-item 
          :index="'1-' + (index + 1)" 
          v-if="item.length == 0"
          @click="goList(keyName)"
          >{{keyName}}</el-menu-item>
        </blockquote>
      </el-submenu>
      <el-menu-item index="2" @click="onCollege"><i class="el-icon-document"></i>院校资讯</el-menu-item>
      <el-menu-item index="3"
        ><i class="el-icon-document"></i>
        <router-link to="/home/daywords" tag="span" style="color: #909399">每日一句</router-link>
      </el-menu-item>
    </el-menu>
    <!-- 管理者页面 -->
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      v-if="this.$store.state.user.utype == 1"
    >
      <el-menu-item index="1"
        ><i class="el-icon-user"></i>
        <router-link to="/home/userInfo">用户管理信息管理</router-link>
        </el-menu-item
      >
      <el-menu-item index="2"><i class="el-icon-s-management"></i>
      <router-link to="/home/filecenter">文件管理</router-link></el-menu-item>
    </el-menu>
    <el-main>
      <!-- 内容显示区域 -->
      <router-view></router-view>
    </el-main>
    <el-footer>
      2023&nbsp;&nbsp;&copy;&nbsp;&nbsp;&nbsp;河南机电职业学院
    </el-footer>
  </el-container>
</template>

<script>
import { subjects,collegewebsites } from "../api/myReq";
export default {
  name: "Home",
  data() {
    return {
      isflag: false,
      subject: {},
      activeIndex: "1",
      webCollege:{}
    };
  },
  methods: {
    changeblock() {
      this.isflag = !this.isflag;
    },
    jumpHome() {
      this.$store.commit("EXIT");
      this.$router.push("/login");
    },
    /* 院校查询 */
    onCollege(){
      const tSchool = this.$store.state.user.tschool;
      if(this.webCollege[tSchool]){
        window.open(this.webCollege[tSchool]);
      }else{
        window.open("https://yz.chsi.com.cn/");
      }
    },
    goList(value){
       this.activeDate = new Date();
      this.$router.push("/home/list?sname=" + value);
    }
  },
  mounted() {
    subjects().then((resp) => {
      this.subject = resp.data.data[0];
    });
  collegewebsites().then((resp)=>{
    this.webCollege = resp.data.data[0];
      })
  },
};
</script>

<style scoped>
.el-header {
  position: relative;
  width: 100%;
  height: 60px;
  background-color: black;
  padding: 15px 40px;
}
span{
  color: #fff;
}
.el-header .img {
  height: 40px;
  width: 40px;
  background-color: #1e95db;
  
}
.el-header .img img{
  width: 100%;
  height: 100%;
}
.el-header i {
  color: red;
  font-size: 19px;
  padding: 4px;
}
.title-right span {
  display: block;
  height: 40px;
  font-size: 20px;
  background-color: brown;
}
.title-right {
  position: absolute;
  top: 20px;
  right: 40px;
}
.title-right .block {
  position: absolute;
  top: 40px;
  right: 0px;
  width: 150px;
  height: 70px;
  background-color: #f9f9f9;
  z-index: 999;
}
.title-right .right-item {
  text-align: center;
  color: #fff;
}
.el-menu-item a {
  text-decoration: none;
}
.el-footer {
  display: flex;
  align-items: center;
  color: white;
  font-size: 16px;
  background-color: #f9f9f9;
  color: #58666e;
}
.router-link-active{
  text-decoration: none;
}
</style>